
import time
from typing import List

import pytest
from faker import Faker

from pytest_pratice.caculator import Caculator

# 转码插件更改
def pytest_collection_modifyitems(
    session: "Session", config: "Config", items: List["Item"]
) -> None:
    for item in items:
        item.name = item.name.encode('utf-8').decode('unicode-escape')
        item._nodeid = item.nodeid.encode('utf-8').decode('unicode-escape')

# 动态生成日志
@pytest.fixture(scope="session", autouse=True)
def manage_logs(request):
    """Set log file name same as test name"""
    now = time.strftime("%Y-%m-%d %H-%M-%S")
    rootdir = request.config.rootdir
    log_name = rootdir+'/output/log/' + now + '.logs'

    request.config.pluginmanager.get_plugin("logging-plugin") \
        .set_log_path(log_name)

@pytest.fixture(scope="class",autouse=False)
def get_cacl():
    cacl = Caculator()
    print("开始计算")
    yield cacl
    print("计算结束")

# 获取中文姓名
@pytest.fixture()
def get_uesrname():
    fake = Faker("zh_CN")
    name = fake.name()
    yield name
# 获取手机号码
@pytest.fixture()
def get_phonenum():
    fake = Faker("zh_CN")
    phonenum = fake.phone_number()
    yield phonenum
# 获取账户id
@pytest.fixture()
def get_accountid():
    fake = Faker("zh_CN")
    accountid = fake.phone_number()
    yield accountid

if __name__ == '__main__':
        get_accountid()